package com.franklin.java.api.ui.jpanel;

import com.intellij.ui.components.JBScrollPane;

import java.awt.*;

/**
 * 重写滑动数值方法
 * 滑动是相对于上次的滑动来说
 * @author Franklin
 * @since 2021/2/5 12:12
 */
public class MyJScrollPane extends JBScrollPane {

    private int lastVerticalSlideValue = 0;
    private int lastHorizontalSlideValue = 0;

    public MyJScrollPane(Component view) {
        super(view);
    }

    public int getVerticalScrollSize(){
        return getVerticalScrollBar().getValue() - lastVerticalSlideValue;
    }

    public int getHorizontalScrollSize(){
        return getHorizontalScrollBar().getValue() - lastHorizontalSlideValue;
    }

    /**
     * 保存上次滑动的位置<br>
     * @author Franklin
     * @since 2021/2/5 16:28
     * @param :
     * @return void
     */
    public void saveLastSlideValue() {
        lastHorizontalSlideValue = getHorizontalScrollBar().getValue();
        lastVerticalSlideValue = getVerticalScrollBar().getValue();
    }
}
